package com.of.controller;

import com.of.pojo.Orders;
import com.of.service.OrdersService;
import com.of.vo.PageResult;
import com.of.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @GetMapping("/list")
    public SysResult findOrdersList(PageResult pageResult){//3
        pageResult = ordersService.findOrdersList(pageResult);//+2
        return SysResult.success(pageResult);
    }

    @DeleteMapping("/{id}")
    public SysResult deleteOrdersById(@PathVariable Integer id){
        ordersService.deleteOrdersById(id);
        return SysResult.success();
    }



    @PostMapping("/addOrders")
    public SysResult saveOrders(@RequestBody Orders orders){
        ordersService.saveOrders(orders);
        return SysResult.success();
    }


    @GetMapping("/{id}")
    public SysResult findOrdersById(@PathVariable Integer id){

        Orders orders = ordersService.findOrdersById(id);
        return SysResult.success(orders);
    }


    @PutMapping("/updateOrderss")
    public SysResult updateOrders(@RequestBody Orders orders){
        ordersService.updateOrders(orders);
        return SysResult.success();
    }
}
